<template>
  <div class="stats" v-if="todos.length > 0">
    <span>{{ remaining }} 项未完成</span>
    <button 
      @click="clearCompleted" 
      v-if="todos.length > remaining"
      class="clear-btn"
    >
      清除已完成
    </button>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, computed } from 'vue';

const props = defineProps({
  todos: {
    type: Array,
    required: true
  }
});

const emit = defineEmits(['clear-completed']);

const remaining = computed(() => {
  return props.todos.filter(todo => !todo.completed).length;
});

const clearCompleted = () => {
  emit('clear-completed');
};
</script>

<style scoped>
.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid #eee;
  color: #666;
}

.clear-btn {
  padding: 5px 10px;
  background-color: #ff6b6b;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.clear-btn:hover {
  background-color: #ff5252;
}
</style>